/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.transaction.annotation;

import java.lang.reflect.AnnotatedElement;

import org.springframework.lang.Nullable;
import org.springframework.transaction.interceptor.TransactionAttribute;

/**
 * 解析已知事务注释类型的策略接口。
 * {@link AnnotationTransactionAttributeSource}委托给这样的解析器，以支持特定的注解类型，
 * 比如Spring自己的{@link Transactional}， JTA 1.2的{@link javax.transaction.Transactional}或EJB3的{@link javax.ejb.TransactionAttribute}。
 *
 * @author Juergen Hoeller
 * @since 2.5
 * @see AnnotationTransactionAttributeSource
 * @see SpringTransactionAnnotationParser
 * @see Ejb3TransactionAnnotationParser
 * @see JtaTransactionAnnotationParser
 */
public interface TransactionAnnotationParser {

	/**
	 * 确定给定的类是否是事务属性的候选类{@code TransactionAnnotationParser}的注解格式。
	 * 如果该方法返回{@code false}，则表示给定类上的方法将不会被{@code #parseTransactionAnnotation}检查遍历。
	 * 因此，返回{@code false}是对non-affected的优化类，
	 * 而{@code true}仅仅意味着类需要获取对给定类上的每个方法进行完全检查。
	 * @param targetClass the class to introspect
	 * @return {@code false} if the class is known to have no transaction
	 * annotations at class or method level; {@code true} otherwise. The default
	 * implementation returns {@code true}, leading to regular introspection.
	 * @since 5.2
	 */
	default boolean isCandidateClass(Class<?> targetClass) {
		return true;
	}

	/**
	 * 解析给定方法或类的事务属性，
	 * 基于该解析器理解的注释类型。
	 * 这实际上是将一个已知的事务注释解析为Spring的元数据
	 * 属性类。如果方法/类不是事务性的，则返回{@code null}。
	 * @param element the annotated method or class
	 * @return the configured transaction attribute, or {@code null} if none found
	 * @see AnnotationTransactionAttributeSource#determineTransactionAttribute
	 */
	@Nullable
	TransactionAttribute parseTransactionAnnotation(AnnotatedElement element);

}
